// pages/UserStatistics/UserDeatils/UserDeatils.js
const controllers = require('../../controllers/controllerIndex.js').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that =this
    let params={
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
      accountRelationId:options.id
    }
    controllers.accountDetail(
      params
    ).then(res =>{
      let vipList=[]
        if(res.data.vipList&&res.data.vipList.length>0){
          res.data.vipList.forEach(element => {
            let p =0
            if(element.endTime){
            let endTime =that.getDateTime(element.endTime)
            let createTime=that.getDateTime(element.createTime)
           let total= endTime-createTime
           let time = endTime-new Date().getTime(); 
             p =time/total;
           }
           element.p=p*100
           vipList.push(element)
          });
        }
    
      that.setData({
        detail:res.data,
        vipList
      })
    })
  },

  getDateTime(date){
   
    date= date.replace(new RegExp("-","gm"),"/");
    var time = (new Date(date)).getTime(); 
    return time
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})